package com.cndongtai.net;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import com.cndongtai.net.message.Message;

public class NetController {
	
	private static final SocketPool pool = new SocketPool();
	
	private static final Map<String, Message> msgRsp= new HashMap<String, Message>();
	
	private static final BlockingQueue<Message> msgReq = new ArrayBlockingQueue<Message>(100);
	
	public static final Map<String,Long> onlineMap = new HashMap<String,Long>();
	
	public static SocketPool getSocketPool() {
		return pool;
	}
	
	public static Message getMessage(String seq) {
		if(msgRsp.containsKey(seq)) {
			return msgRsp.remove(seq);
		}
		
		return null;
	}
	
	public static void removeMessage(String seq) {
		msgRsp.remove(seq);
	}
	
	public static void setMessage(String seq, Message msg) {
		msgRsp.put(seq, msg);
	}
	
	public static void putMsg(Message msg) {
		try {
			msgReq.put(msg);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Message pollMsg() {
		try {
			return msgReq.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
//		return msgReq.poll();
	}

}
